package com.runing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.runing.config.ResponseWrapper;
import com.runing.entity.RVersion;
import com.runing.mapper.RVersionMapper;
import com.runing.service.RVersionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lel
 * @since 2021-03-11
 */
@Service
public class RVersionServiceImpl extends ServiceImpl<RVersionMapper, RVersion> implements RVersionService {

    @Autowired
    RVersionMapper versionMapper;

    public ResponseWrapper updateVersion(RVersion rVersion){
        if (rVersion == null){
            return ResponseWrapper.markCustom(false,400,"version不能为空",null);
        }else {
            int result = versionMapper.updateById(rVersion);
            if (result == 1){
                return ResponseWrapper.markSuccess(null);
            }else {
                return ResponseWrapper.markError();
            }
        }
    }

    public ResponseWrapper findVersion(){
        QueryWrapper<RVersion> versionQueryWrapper = new QueryWrapper<>();
        versionQueryWrapper.last(" limit 1");
        RVersion version = versionMapper.selectOne(versionQueryWrapper);
        ResponseWrapper wrapper = ResponseWrapper.markSuccess(version);
        wrapper.getData().put("data",version);
        return wrapper;
    }

}
